<?php
/**
*  管理页
* @author: 
*/
defined('IN_ADMIN') ||  exit('Access Denied');

function  insert(){
	    $user = new user();          
        $res = $user->db->insert($_POST);
        if ($res ==false) {
            msg::info('back',$user->db->msg,'error');
        } else {
            msg::info('?mod=user');
        }
}

function  delete(){
	    $user = new user();        
        $ids  = implode(',',util::convert($_REQUEST['ids']));
        $user->db->where(sprintf('id in (%s)',$ids));
        $res = $user->db->delete();
        if ($res ==false) {
            msg::info('back',$user->db->msg,'error');
        } else {
            msg::info('?mod=user');
        }
}

function  update(){
	    $user = new user();		
        $user->db->where('id='.(int)$_GET['id']);
        $res = $user->db->update($_POST);
        if ($res ==false) {
            msg::info('back',$user->db->msg,'error');
        } else {
            msg::info('?mod=user');
        }
        
}
function  add(){
		include template::inc("user/add.php");
}

function  edit(){
	    $user = new user();        
        $user->db->where('id='.(int)$_GET['id']);
        $row = $user->db->find();
		include template::inc("user/edit.php");
}

function  index(){
	    $user = new user();        
        $url = "?mod=$mod&page=_page_";
        if ($key=get($_GET,'key')) {
            $where = util::convert($_GET['field']).' like "%'.util::convert($key).'%"';
            $user->db->where($where);
            $url .= "&field={$_GET['field']}&key=$key";
            
        }
        if ($cnt = $user->db->count() ) {
            $o = array('size'=>20);//每页显示的记录数
            $pages = new pages($cnt,$o);
            $sql = sprintf("select * from %s %s order by id desc", $user->db->table, $user->db->condition());
            $rows = $user->db->rows($sql,$pages->start,$o['size']);
            $nav = $pages->show();         
        }
		include template::inc("user/index.php"); 
}


